import { Ref } from 'vue';

export default (getData: () => void) => {
  const showState = inject('showState') as { isShow: Ref<boolean> };
  let timer: NodeJS.Timeout | null = null;
  onMounted(() => {
    const DELAYTIME = 20000;
    timer = setInterval(() => {
      if (showState.isShow.value) {
        getData();
      }
    }, DELAYTIME);
  });
  onBeforeUnmount(() => {
    timer && clearInterval(timer);
  });
};
